﻿using Microsoft.Extensions.Configuration;

namespace Common.Helper
{
    public class AppSettings
    {

        public AppSettings(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        static IConfiguration Configuration { get; set; }

        public static string App(params string[] sections)
        {
            try
            {
                if (sections.Any())
                {
                    return Configuration[string.Join(":", sections)];
                }
            }
            catch (Exception)
            {

            }
            return "";
        }
        /// <summary>
        /// 递归获取配置信息数组
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sections"></param>
        /// <returns></returns>
        public static List<T> App<T>(params string[] sections)
        {
            List<T> list = new List<T>();
            Configuration.Bind(string.Join(":", sections), list);
            return list;
        }

    }
}
